#include <assert.h>
#include <imbus.h>
#include <stdio.h>
#include <string.h>

int main (int argc, char *argv [])
{
    IMHashTable *table;
    IMHashIterator *iter;

    IMInt i;
    IMChar key [10];
    IMChar val [100];

    table = im_hash_table_new_full (im_str_hash, im_str_equal, im_free, im_free);

    for (i=1; i < 100; ++i) {
        snprintf (key, 10, "str%02d", i);
        snprintf (val, 100, "This is the %d string.", i);

        im_hash_table_insert (table, strdup (key), strdup (val));
    }

    iter = im_hash_table_get_iterator (table);
    i = 0;
    while (im_hash_iterator_valid (iter)) {
        IMPointer key, val;

        if (im_hash_iterator_get (iter, &key, &val))
            printf ("%5s - %s\n", (IMChar *)key, (IMChar *)val);

        if (i++ % 2)
            im_hash_iterator_remove (iter);

        im_hash_iterator_next (iter);
    }
    im_hash_iterator_destroy (iter);

    printf ("\nRemoved odd entries:\n");
    iter = im_hash_table_get_iterator (table);
    while (im_hash_iterator_valid (iter)) {
        IMPointer key, val;

        if (im_hash_iterator_get (iter, &key, &val))
            printf ("%5s - %s\n", (IMChar *)key, (IMChar *)val);

        im_hash_iterator_next (iter);
    }

    printf ("\n\nstr65: %s\n", (IMChar *) im_hash_table_lookup (table, "str65"));
    printf ("str04: %s\n", (IMChar *) im_hash_table_lookup (table, "str04"));

    im_hash_iterator_destroy (iter);

    im_hash_table_destroy (table);

    return 0;
}
/*
vi:ts=4:nowrap:ai:expandtab
*/
